package com.example.administrator.myapplication;

import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.example.administrator.myapplication.fragment.NewListFragment;
import com.example.administrator.myapplication.fragment.NewListFragment3;
import com.example.administrator.myapplication.fragment.NewListFragment4;
import com.example.administrator.myapplication.fragment.NewsListFragment2;

public class MainActivity extends AppCompatActivity {

    private TextView textView1;
    private TextView textView2;
    private TextView textView3;
    private TextView textView4;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        initData();
        initEvent();
    }
    private void initView(){
        textView1 = findViewById(R.id.fragment1);
        textView2 = findViewById(R.id.fragment2);
        textView3 = findViewById(R.id.fragment3);
        textView4 = findViewById(R.id.fragment4);

    }
    private void initData(){

    }
    private void initEvent(){
textView1.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        NewListFragment newListFragment=new NewListFragment();//实例化fragment对象
        //获取fragment实例
        //从fragmentManager中获取fragment事务并开启
        getFragmentManager().beginTransaction().replace(R.id.fragment_replace_main,newListFragment).commit();
    }
});textView2.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        NewsListFragment2 newsListFragment2=new NewsListFragment2();//实例化fragment对象
        getFragmentManager().beginTransaction().replace(R.id.fragment_replace_main,newsListFragment2).commit();
    }
});textView3.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        NewListFragment3 newListFragment3=new NewListFragment3();//实例化fragment对象
        getFragmentManager().beginTransaction().replace(R.id.fragment_replace_main,newListFragment3).commit();
    }
});textView4.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        NewListFragment4 newListFragment4=new NewListFragment4();//实例化fragment对象
        getFragmentManager().beginTransaction().replace(R.id.fragment_replace_main,newListFragment4).commit();
    }
});
    }
}
